#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/22 11:02
# @Author: scg
# @Email: xxx@gmail.com
# @File：clue_add_page.py

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_page import BasePage


class ClueAddPage(BasePage):
    url = '/crm/index.php?m=leads&a=add'

    company_locator = (By.ID, 'name')
    source_locator = (By.ID, 'source')
    contacts_locator = (By.ID, 'contacts_name')
    save_btn_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')

    def input_company(self, name):
        self.driver.find_element(*self.company_locator).send_keys(name)

    def select_source(self, visible_text):
        source_element = self.driver.find_element(*self.source_locator)
        select = Select(source_element)
        select.select_by_visible_text(visible_text)

    def input_contact(self, name):
        self.driver.find_element(*self.contacts_locator).send_keys(name)

    def click_save_btn(self):
        self.driver.find_element(*self.save_btn_locator).click()
